/*
 * 作者：姚俊
 * 功能：论文的逻辑处理
 * 日期：2015-05-29
 */
package admin.service.fruits;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import beanDao.MapToBean;

import teacher.bean.Paper;
import teacher.bean.Teacher;
import tools.StringDate;
import database.dao.MysqlCrud;

public class PaperService {
	
	
	/**
	 * @category 根据论文的ID来查询一个论文
	 * @author yaojun
	 * @param Paper Paper 传入一个论文信息的对象，该对象必须有论文信息的ID
	 * @return Paper 返回的是一个论文信息的对象
	 */
	public Paper getPaper(Paper paper)
	{
		Paper pap =new Paper();
		String sql="select * from Paper where papId=?";
		String[]  parameter={String.valueOf(paper.getPapId())};
        MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> lists=mysqlcurd.SelectData(sql, parameter);
		if(lists.size()>0&&lists!=null)
		{	
			Map map=lists.get(0);
			pap=new MapToBean().MapToPaper(map);
		}
		
		return pap;
	}	
	
	/**
	 * @category 根据论文信息的ID来修改这个论文的信息
	 * @author yaojun
	 * @param inn1 Paper 传入一个要用于修改的Paper对象
	 * @param inn2 Paper 传入一个根据这个Paper对象的ID来查找需要修改的哪一条论文信息数据
	 * @return boolean 成功则返回true
	 */
	public boolean updatePaper(Paper paper1,Paper paper2)
	{
		boolean b=false;
		String sql="update Paper set name=?,fauthor=?," +
		"pbulication=?,pubNumber=?,include=?,quoteNum=?," +
		"state=?,upload=?,pubPage=?,date=?,topStu=?,tauthor=?," +
		"oauthor=?,volume=?,teaId=?,type=?,esi=?,jclass=?," +
		"includNum=?,meetClass=?,meetName=?,meetPlace=? where papId=?";
		
		String[] parameter={
				String.valueOf(paper1.getName()),
				String.valueOf(paper1.getFauthor()),
				String.valueOf(paper1.getPbulication()),
				String.valueOf(paper1.getPubNumber()),
				String.valueOf(paper1.getInclude()),
				String.valueOf(paper1.getQuoteNum()),
				String.valueOf(paper1.getState()),
				String.valueOf(paper1.getUpload()),
				String.valueOf(paper1.getPubPage()),
				String.valueOf(StringDate.DateToString(paper1.getDate())),
				String.valueOf(paper1.getTopStu()),
				String.valueOf(paper1.getTauthor()),
				String.valueOf(paper1.getOauthor()),
				String.valueOf(paper1.getVolume()),
				String.valueOf(paper1.getTeaId()),
				
				String.valueOf(paper1.getType()),
				String.valueOf(paper1.getEsi()),
				String.valueOf(paper1.getJclass()),
				String.valueOf(paper1.getIncludNum()),
				String.valueOf(paper1.getMeetClass()),
				String.valueOf(paper1.getMeetName()),
				String.valueOf(paper1.getMeetPlace()),
				String.valueOf(paper2.getPapId())
		};
		
		MysqlCrud mysqlcurd=new MysqlCrud();
		b=mysqlcurd.InsertAndUpdateData(sql, parameter);
		return b;
	}

	
	/**
	 * @category 对查询所有论文进行分页
	 * @param pageSize int 一个页面要显示pageSize条个数据
	 * @param pageNow int 从pageNow当前的数据来显示
	 * @return papers List<Paper> 返回查询到的论文列表
	 */
	public List<Paper> getSegregatePaperByAll(int pageNow,int pageSize) {
		String sql= "select * from (select * from paper order by state,type,jclass,meetClass,include,date desc) as P WHERE P.state>3 and P.papId LIMIT " +
				""+(pageNow-1)+" ,"+pageSize+"";
		int i=0;
		List<Paper> papers=new ArrayList<Paper>();
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		while(i<list.size()){
			Map map=list.get(i);
			papers.add(new MapToBean().MapToPaper(map));
			i++;
		}
		return papers;
	}
	
	
	/**
	 * @category 根据名称对查询所有论文进行分页
	 * @param pageSize int 一个页面要显示pageSize条个数据
	 * @param pageNow int 从pageNow当前的数据来显示
	 * @param name String 论文的名称
	 * @return papers List<Paper> 返回查询到的论文列表
	 * 
	 */
	public List<Paper> getSegregatePaperByName(String name,int pageNow,int pageSize) {
		String sql= "select * from (select * from paper order by state,type,jclass,meetClass,include,date desc) as P WHERE P.state>3 and P.name like '%"+name+"%' and P.papId LIMIT " +
				""+(pageNow-1)+" ,"+pageSize+"";
		int i=0;
		List<Paper> papers=new ArrayList<Paper>();
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		while(i<list.size()){
			Map map=list.get(i);
			papers.add(new MapToBean().MapToPaper(map));
			i++;
		}
		return papers;
	}
	
	
	/**
	 * @category 根据名称对查询所有论文进行分页
	 * @param pageSize int 一个页面要显示pageSize条个数据
	 * @param pageNow int 从pageNow当前的数据来显示
	 * @param date1 Date 开始日期
	 * @param date2 Date 结束日期
	 * @return papers List<Paper> 返回查询到的论文列表
	 * 
	 */
	public List<Paper> getSegregatePaperByDate(Date date1,Date date2,int pageNow,int pageSize) {
		String sql= "select * from (select * from paper order by state,type,jclass,meetClass,include,date desc) as P WHERE P.state>3 and P.date>='"+date1+"' and P.date<='"+date2+"' and P.papId LIMIT " +
				""+(pageNow-1)+" ,"+pageSize+"";
		int i=0;
		List<Paper> papers=new ArrayList<Paper>();
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		while(i<list.size()){
			Map map=list.get(i);
			papers.add(new MapToBean().MapToPaper(map));
			i++;
		}
		return papers;
	}
	
	
	/**
	 * @category 根据名称统计论文的数量
	 * @return sum int 论文的数量
	 */
		public int getCountPaperByName(String name)
		{
			String sql=null;
			int count=0;
			if(name.equals("")||name==null)
			{
				sql="select count(*) from paper where state>3";
			}
			else
			{
				sql="select count(*) from paper where state>3 and name like '%"+name+"%'";
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, null);
			Map map=lists.get(0);
			count=Integer.parseInt(map.get(0).toString());
			return count;
		}
		
		
		/**
		 * @category 根据日期统计论文的数量
		 * @return count int 论文的数量
		 */
		public int getCountPaperByDate(Date date1,Date date2)
		{
			int count=0;
			String sql="select count(*) from paper where state>3 and date>='"+date1+"' and date<='"+date2+"'";
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, null);
			Map map=lists.get(0);
			count=Integer.parseInt(map.get(0).toString());
			return count;
		}
		
		/**
		 * @author yaojun
		 * @category 按照审核状态来分页查询所有的论文
		 * @param state 4表示未审核，5表示已经审核
		 * @return List
		 */
		public List<Paper> getSegregatePaperByState(int state,int pageNow,int pageSize) {
			String sql= "select * from paper WHERE state=? and papId LIMIT " +
					""+(pageNow-1)+" ,"+pageSize+"";
			int i=0;
			List<Paper> papers=new ArrayList<Paper>();
			MysqlCrud mysqlcurd=new MysqlCrud();
			String[]  parameter={String.valueOf(state)};
			List<Map> list = mysqlcurd.SelectData(sql, parameter);
			//System.out.println(list.size());
			while(i<list.size()){
				Map map=list.get(i);
				papers.add(new MapToBean().MapToPaper(map));
				i++;
			}
			return papers;
		}
		
		
		/**
		 * @author yaojun
		 * @category 根据状态统计论文的数量
		 * @return count int 论文的数量
		 */
		public int getCountPaperByState(int state)
		{
			int count=0;
			String sql="select count(*) from paper where state=?";
			MysqlCrud mysqlcurd=new MysqlCrud();
			String[]  parameter={String.valueOf(state)};
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			Map map=lists.get(0);
			count=Integer.parseInt(map.get(0).toString());
			return count;
		}
		/**
		 * @author yaojun
		 * @category 根据不同的条件查询不同的数量
		 * @return count int 论文的数量
		 */
		public int getCountPaper(Paper paper)
		{
			int count=0;
			String sql="select count(*) from paper ";
			List<String> sql1=new ArrayList<String>();
			List<String> paras=new ArrayList<String>();
			if(paper!=null)
			{
				if(paper.getDate()!=null)
				{
					sql1.add(" date=? ");
					paras.add(String.valueOf(paper.getDate()));
				}
				if(paper.getName()!=null)
				{
					sql1.add(" name like ? ");
					paras.add("%"+String.valueOf(paper.getName())+"%");
				}
				if(paper.getMeetName()!=null)
				{
					sql1.add(" P.meetName like ? ");
					paras.add("%"+String.valueOf(paper.getMeetName())+"%");
				}
				if(paper.getEsi()!=null)
				{
					sql1.add(" esi=? ");
					paras.add(String.valueOf(paper.getEsi()));
				}
				if(paper.getFauthor()!=null)
				{
					sql1.add(" P.fauthor like ? ");
					paras.add("%"+String.valueOf(paper.getFauthor())+"%");
				}
				if(paper.getInclude()!=null)
				{
					sql1.add(" include=? ");
					paras.add(String.valueOf(paper.getInclude()));
				}
				if(paper.getJclass()!=null)
				{
					sql1.add(" jclass=? ");
					paras.add(String.valueOf(paper.getJclass()));
				}
				if(paper.getPapId()!=null)
				{
					sql1.add(" papId=? ");
					paras.add(String.valueOf(paper.getPapId()));
				}
				if(paper.getPbulication()!=null)
				{
					sql1.add(" publication=? ");
					paras.add(String.valueOf(paper.getPbulication()));
				}
				if(paper.getPubPage()!=null)
				{
					sql1.add(" pubPage=? ");
					paras.add(String.valueOf(paper.getPubPage()));
				}
				if(paper.getType()!=null)
				{
					sql1.add(" type=? ");
					paras.add(String.valueOf(paper.getType()));
				}
			}
			
			for(int i=0;i<sql1.size();i++)
			{
				if(i==0)
					sql+="where"+sql1.get(0);
				else
					sql+="and"+sql1.get(i);
			}
			String[] parameter=new String[paras.size()];
			for(int i=0;i<paras.size();i++)
			{
				parameter[i]=paras.get(i);
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			Map map=lists.get(0);
			count=Integer.parseInt(map.get(0).toString());
			return count;
		}
		
		
		/**
		 * @category 按照所有条件查询所有论文进行分页
		 * @param pageSize int 一个页面要显示pageSize条个数据
		 * @param pageNow int 从pageNow当前的数据来显示
		 * @param date1 Date 开始日期
		 * @param date2 Date 结束日期
		 * @return papers List<Paper> 返回查询到的论文列表
		 * 
		 */
		public List<Paper> getSegregatePaperByDirection(Paper paper,String date2,int direction,int pageNow,int pageSize,int state,List<String> orders) {
//			String sql= "select * from paper WHERE date>='"+date1+"' and date<='"+date2+"' and papId LIMIT " +
//					""+(pageNow-1)+" ,"+pageSize+"";
			String sql=null;
			if(orders.size()>0)
			{
				String sqlOrder="";
				for(int i=0;i<orders.size();i++)
				{
					if(i!=orders.size()-1)
						sqlOrder+=orders.get(i)+",";
					else
						sqlOrder+=orders.get(i);
						
				}
				sql="select * from (select * from paper order by "+sqlOrder+") as p,teacher as t where p.teaId=t.teaId and t.direction=? and p.state>'"+state+"'";
			}
			else
			sql="select * from paper as P,teacher as T where P.teaId=T.teaId and T.direction=? and p.state>'"+state+"' ";
			int j=0;
			String sql2=" and papId LIMIT "+(pageNow-1)+" ,"+pageSize+" ";
			List<Paper> papers=new ArrayList<Paper>();
			List<String> sql1=new ArrayList<String>();
			List<String> paras=new ArrayList<String>();
			
			paras.add(String.valueOf(direction));
			if(paper!=null)
			{
				if(paper.getDate()!=null)
				{
					sql1.add(" P.date>=? and P.date<=? ");
					paras.add(String.valueOf(paper.getDate()));
					paras.add(date2);
				}
				if(paper.getName()!=null)
				{
					sql1.add(" P.name like ? ");
					paras.add("%"+String.valueOf(paper.getName())+"%");
				}
				if(paper.getMeetName()!=null)
				{
					sql1.add(" P.meetName like ? ");
					paras.add("%"+String.valueOf(paper.getMeetName())+"%");
				}
				if(paper.getEsi()!=null)
				{
					sql1.add(" P.esi=? ");
					paras.add(String.valueOf(paper.getEsi()));
				}
				if(paper.getFauthor()!=null)
				{
					sql1.add(" P.fauthor like ? ");
					paras.add("%"+String.valueOf(paper.getFauthor())+"%");
				}
				if(paper.getInclude()!=null)
				{
					sql1.add(" P.include=? ");
					paras.add(String.valueOf(paper.getInclude()));
				}
				if(paper.getJclass()!=null)
				{
					sql1.add(" P.jclass=? ");
					paras.add(String.valueOf(paper.getJclass()));
				}
				if(paper.getPapId()!=null)
				{
					sql1.add(" P.papId=? ");
					paras.add(String.valueOf(paper.getPapId()));
				}
				if(paper.getPbulication()!=null)
				{
					sql1.add(" P.pbulication like ? ");
					paras.add("%"+String.valueOf(paper.getPbulication())+"%");
				}
				if(paper.getPubPage()!=null)
				{
					sql1.add(" P.pubPage=? ");
					paras.add(String.valueOf(paper.getPubPage()));
				}
				if(paper.getType()!=null)
				{
					sql1.add(" P.type=? ");
					paras.add(String.valueOf(paper.getType()));
				}
				if(paper.getPubNumber()!=null)
				{
					sql1.add(" P.pubNumber=? ");
					paras.add(String.valueOf(paper.getPubNumber()));
				}
				if(paper.getTopStu()!=null)
				{
					sql1.add(" P.topStu=? ");
					paras.add(String.valueOf(paper.getTopStu()));
				}
				if(paper.getTauthor()!=null)
				{
					sql1.add(" P.tauthor like ? ");
					paras.add("%"+String.valueOf(paper.getTauthor())+"%");
				}
				if(paper.getOauthor()!=null)
				{
					sql1.add(" P.oauthor like ? ");
					paras.add("%"+String.valueOf(paper.getOauthor())+"%");
				}
				if(paper.getMeetClass()!=null)
				{
					sql1.add(" P.meetClass=? ");
					paras.add(String.valueOf(paper.getMeetClass()));
				}
			}
			
			for(int i=0;i<sql1.size();i++)
			{
					sql+="and"+sql1.get(i);
			}
			
			//加入最后一个,该字符是用于分页
			sql+=sql2;
		//	System.out.println("与拒绝："+sql);
			String[] parameter=new String[paras.size()];
			for(int i=0;i<paras.size();i++)
			{
				parameter[i]=paras.get(i);
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			//System.out.println(list.size());
			while(j<lists.size()){
				Map map=lists.get(j);
				papers.add(new MapToBean().MapToPaper(map));
				j++;
			}
			return papers;
		}
		
		
		/**
		 * @category 按照不同的条件，根据名称对查询所有论文
		 * @param date1 Date 开始日期
		 * @param date2 Date 结束日期
		 * @return papers List<Paper> 返回查询到的论文列表
		 * 
		 */
		public List<Paper> getPaperByDirection(Paper paper,String date2,int direction,int state) {
//			String sql= "select * from paper WHERE date>='"+date1+"' and date<='"+date2+"' and papId LIMIT " +
//					""+(pageNow-1)+" ,"+pageSize+"";
			String sql="select * from paper as P,teacher as T where P.teaId=T.teaId and T.direction=? and state>'"+state+"' ";
			int j=0;
			List<Paper> papers=new ArrayList<Paper>();
			List<String> sql1=new ArrayList<String>();
			List<String> paras=new ArrayList<String>();
			
			paras.add(String.valueOf(direction));
			if(paper!=null)
			{
				if(paper.getDate()!=null)
				{
					sql1.add(" P.date>=? and P.date<=? ");
					paras.add(String.valueOf(paper.getDate()));
					paras.add(date2);
				}
				if(paper.getName()!=null)
				{
					sql1.add(" P.name like ? ");
					paras.add("%"+String.valueOf(paper.getName())+"%");
				}
				if(paper.getMeetName()!=null)
				{
					sql1.add(" P.meetName like ? ");
					paras.add("%"+String.valueOf(paper.getMeetName())+"%");
				}
				if(paper.getEsi()!=null)
				{
					sql1.add(" P.esi=? ");
					paras.add(String.valueOf(paper.getEsi()));
				}
				if(paper.getFauthor()!=null)
				{
					sql1.add(" P.fauthor like ? ");
					paras.add("%"+String.valueOf(paper.getFauthor())+"%");
				}
				if(paper.getInclude()!=null)
				{
					sql1.add(" P.include=? ");
					paras.add(String.valueOf(paper.getInclude()));
				}
				if(paper.getJclass()!=null)
				{
					sql1.add(" P.jclass=? ");
					paras.add(String.valueOf(paper.getJclass()));
				}
				if(paper.getPapId()!=null)
				{
					sql1.add(" P.papId=? ");
					paras.add(String.valueOf(paper.getPapId()));
				}
				if(paper.getPbulication()!=null)
				{
					sql1.add(" P.pbulication like ? ");
					paras.add("%"+String.valueOf(paper.getPbulication())+"%");
				}
				if(paper.getPubPage()!=null)
				{
					sql1.add(" P.pubPage=? ");
					paras.add(String.valueOf(paper.getPubPage()));
				}
				if(paper.getType()!=null)
				{
					sql1.add(" P.type=? ");
					paras.add(String.valueOf(paper.getType()));
				}
				if(paper.getPubNumber()!=null)
				{
					sql1.add(" P.pubNumber=? ");
					paras.add(String.valueOf(paper.getPubNumber()));
				}
				if(paper.getTopStu()!=null)
				{
					sql1.add(" P.topStu=? ");
					paras.add(String.valueOf(paper.getTopStu()));
				}
				if(paper.getTauthor()!=null)
				{
					sql1.add(" P.tauthor like ? ");
					paras.add("%"+String.valueOf(paper.getTauthor())+"%");
				}
				if(paper.getOauthor()!=null)
				{
					sql1.add(" P.oauthor like ? ");
					paras.add("%"+String.valueOf(paper.getOauthor())+"%");
				}
				if(paper.getMeetClass()!=null)
				{
					sql1.add(" P.meetClass=? ");
					paras.add(String.valueOf(paper.getMeetClass()));
				}
			}
			
			for(int i=0;i<sql1.size();i++)
			{
				sql+="and"+sql1.get(i);
			}
			
			String[] parameter=new String[paras.size()];
			for(int i=0;i<paras.size();i++)
			{
				parameter[i]=paras.get(i);
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			//System.out.println(list.size());
			while(j<lists.size()){
				Map map=lists.get(j);
				papers.add(new MapToBean().MapToPaper(map));
				j++;
			}
			return papers;
		}
		
		
		/**
		 * @category 按照不同的条件查找所有的论文
		 * @param date1 Date 开始日期
		 * @param date2 Date 结束日期
		 * @return papers List<Paper> 返回查询到的论文列表
		 * 
		 */
		public List<Paper> getPaperByAll(Paper paper,String date2,int direction,int state) {
//			String sql= "select * from paper WHERE date>='"+date1+"' and date<='"+date2+"' and papId LIMIT " +
//					""+(pageNow-1)+" ,"+pageSize+"";
			String sql="select * from paper as P,teacher as T where P.teaId=T.teaId and T.direction=? and state>'"+state+"' ";
			int j=0;
			List<Paper> papers=new ArrayList<Paper>();
			List<String> sql1=new ArrayList<String>();
			List<String> paras=new ArrayList<String>();
			paras.add(String.valueOf(direction));
			
			
			if(paper!=null)
			{
				if(paper.getDate()!=null)
				{
					sql1.add(" P.date>=? and P.date<=? ");
					paras.add(String.valueOf(paper.getDate()));
					paras.add(date2);
				}
				if(paper.getName()!=null)
				{
					sql1.add(" P.name like ? ");
					paras.add("%"+String.valueOf(paper.getName())+"%");
				}
				if(paper.getMeetName()!=null)
				{
					sql1.add(" P.meetName like ? ");
					paras.add("%"+String.valueOf(paper.getMeetName())+"%");
				}
				if(paper.getEsi()!=null)
				{
					sql1.add(" P.esi=? ");
					paras.add(String.valueOf(paper.getEsi()));
				}
				if(paper.getFauthor()!=null)
				{
					sql1.add(" P.fauthor like ? ");
					paras.add("%"+String.valueOf(paper.getFauthor())+"%");
				}
				if(paper.getInclude()!=null)
				{
					sql1.add(" P.include=? ");
					paras.add(String.valueOf(paper.getInclude()));
				}
				if(paper.getJclass()!=null)
				{
					sql1.add(" P.jclass=? ");
					paras.add(String.valueOf(paper.getJclass()));
				}
				if(paper.getPapId()!=null)
				{
					sql1.add(" P.papId=? ");
					paras.add(String.valueOf(paper.getPapId()));
				}
				if(paper.getPbulication()!=null)
				{
					sql1.add(" P.pbulication like ? ");
					paras.add("%"+String.valueOf(paper.getPbulication())+"%");
				}
				if(paper.getPubPage()!=null)
				{
					sql1.add(" P.pubPage=? ");
					paras.add(String.valueOf(paper.getPubPage()));
				}
				if(paper.getType()!=null)
				{
					sql1.add(" P.type=? ");
					paras.add(String.valueOf(paper.getType()));
				}
				if(paper.getPubNumber()!=null)
				{
					sql1.add(" P.pubNumber=? ");
					paras.add(String.valueOf(paper.getPubNumber()));
				}
				if(paper.getTopStu()!=null)
				{
					sql1.add(" P.topStu=? ");
					paras.add(String.valueOf(paper.getTopStu()));
				}
				if(paper.getTauthor()!=null)
				{
					sql1.add(" P.tauthor like ? ");
					paras.add("%"+String.valueOf(paper.getTauthor())+"%");
				}
				if(paper.getOauthor()!=null)
				{
					sql1.add(" P.oauthor like ? ");
					paras.add("%"+String.valueOf(paper.getOauthor())+"%");
				}
				if(paper.getMeetClass()!=null)
				{
					sql1.add(" P.meetClass=? ");
					paras.add(String.valueOf(paper.getMeetClass()));
				}
			}
			
			for(int i=0;i<sql1.size();i++)
			{
				sql+="and"+sql1.get(i);
			}
			
			String[] parameter=new String[paras.size()];
			for(int i=0;i<paras.size();i++)
			{
				parameter[i]=paras.get(i);
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			//System.out.println(list.size());
			while(j<lists.size()){
				Map map=lists.get(j);
				papers.add(new MapToBean().MapToPaper(map));
				j++;
			}
			return papers;
		}
		
		
		/**
		 * @author yaojun
		 * @category 根据不同条件来查询论文的数量，在特定的方向上
		 * @return int
		 * 
		 */
		public int getPaperCountByDirection(Paper paper,String date2,int direction,int state) {
//			String sql= "select * from paper WHERE date>='"+date1+"' and date<='"+date2+"' and papId LIMIT " +
//					""+(pageNow-1)+" ,"+pageSize+"";
			String sql="select count(*)from paper as P,teacher as T where P.teaId=T.teaId and T.direction=? and state>"+state+" ";
			int count=0;
			List<String> sql1=new ArrayList<String>();
			List<String> paras=new ArrayList<String>();
			
			paras.add(String.valueOf(direction));
			if(paper!=null)
			{
				if(paper.getDate()!=null)
				{
					sql1.add(" P.date>=? and P.date<=? ");
					paras.add(String.valueOf(paper.getDate()));
					paras.add(date2);
				}
				if(paper.getName()!=null)
				{
					sql1.add(" P.name like ? ");
					paras.add("%"+String.valueOf(paper.getName())+"%");
				}
				if(paper.getMeetName()!=null)
				{
					sql1.add(" P.meetName like ? ");
					paras.add("%"+String.valueOf(paper.getMeetName())+"%");
				}
				if(paper.getEsi()!=null)
				{
					sql1.add(" P.esi=? ");
					paras.add(String.valueOf(paper.getEsi()));
				}
				if(paper.getFauthor()!=null)
				{
					sql1.add(" P.fauthor like ? ");
					paras.add("%"+String.valueOf(paper.getFauthor())+"%");
				}
				if(paper.getInclude()!=null)
				{
					sql1.add(" P.include=? ");
					paras.add(String.valueOf(paper.getInclude()));
				}
				if(paper.getJclass()!=null)
				{
					sql1.add(" P.jclass=? ");
					paras.add(String.valueOf(paper.getJclass()));
				}
				if(paper.getPbulication()!=null)
				{
					sql1.add(" P.pbulication like ? ");
					paras.add("%"+String.valueOf(paper.getPbulication())+"%");
				}
				if(paper.getType()!=null)
				{
					sql1.add(" P.type=? ");
					paras.add(String.valueOf(paper.getType()));
				}
				if(paper.getPubNumber()!=null)
				{
					sql1.add(" P.pubNumber=? ");
					paras.add(String.valueOf(paper.getPubNumber()));
				}
				if(paper.getTopStu()!=null)
				{
					sql1.add(" P.topStu=? ");
					paras.add(String.valueOf(paper.getTopStu()));
				}
				if(paper.getTauthor()!=null)
				{
					sql1.add(" P.tauthor like ? ");
					paras.add("%"+String.valueOf(paper.getTauthor())+"%");
				}
				if(paper.getOauthor()!=null)
				{
					sql1.add(" P.oauthor like ? ");
					paras.add("%"+String.valueOf(paper.getOauthor())+"%");
				}
				if(paper.getMeetClass()!=null)
				{
					sql1.add(" P.meetClass=? ");
					paras.add(String.valueOf(paper.getMeetClass()));
				}
			}
			
			for(int i=0;i<sql1.size();i++)
			{
				sql+="and"+sql1.get(i);
			}
			String[] parameter=new String[paras.size()];
			for(int i=0;i<paras.size();i++)
			{
				parameter[i]=paras.get(i);
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			Map map=lists.get(0);
			count=Integer.parseInt(map.get(0).toString());
			return count;
		}
		
		
		/**
		 * @author yaojun
		 * @category 根据不同条件来查询所有的论文信息,针对特定的教师工号
		 * @return List
		 * 
		 */
		public List<Paper> getPaperByUser(Paper paper,String date2,Teacher teacher) {
//			String sql= "select * from paper WHERE date>='"+date1+"' and date<='"+date2+"' and papId LIMIT " +
//					""+(pageNow-1)+" ,"+pageSize+"";
			String sql="select * from paper as P,teacher as T where P.teaId=T.teaId and T.user=? ";
			int j=0;
			List<Paper> papers=new ArrayList<Paper>();
			List<String> sql1=new ArrayList<String>();
			List<String> paras=new ArrayList<String>();
			
			paras.add(teacher.getUser());
			if(paper!=null)
			{
				if(paper.getDate()!=null)
				{
					sql1.add(" P.date>=? and P.date<=? ");
					paras.add(String.valueOf(paper.getDate()));
					paras.add(date2);
				}
				if(paper.getName()!=null)
				{
					sql1.add(" P.name like ? ");
					paras.add("%"+String.valueOf(paper.getName())+"%");
				}
				if(paper.getMeetName()!=null)
				{
					sql1.add(" P.meetName like ? ");
					paras.add("%"+String.valueOf(paper.getMeetName())+"%");
				}
				if(paper.getEsi()!=null)
				{
					sql1.add(" P.esi=? ");
					paras.add(String.valueOf(paper.getEsi()));
				}
				if(paper.getFauthor()!=null)
				{
					sql1.add(" P.fauthor like ? ");
					paras.add("%"+String.valueOf(paper.getFauthor())+"%");
				}
				if(paper.getInclude()!=null)
				{
					sql1.add(" P.include=? ");
					paras.add(String.valueOf(paper.getInclude()));
				}
				if(paper.getJclass()!=null)
				{
					sql1.add(" P.jclass=? ");
					paras.add(String.valueOf(paper.getJclass()));
				}
				if(paper.getPapId()!=null)
				{
					sql1.add(" P.papId=? ");
					paras.add(String.valueOf(paper.getPapId()));
				}
				if(paper.getPbulication()!=null)
				{
					sql1.add(" P.pbulication like ? ");
					paras.add("%"+String.valueOf(paper.getPbulication())+"%");
				}
				if(paper.getPubPage()!=null)
				{
					sql1.add(" P.pubPage=? ");
					paras.add(String.valueOf(paper.getPubPage()));
				}
				if(paper.getType()!=null)
				{
					sql1.add(" P.type=? ");
					paras.add(String.valueOf(paper.getType()));
				}
				if(paper.getPubNumber()!=null)
				{
					sql1.add(" P.pubNumber=? ");
					paras.add(String.valueOf(paper.getPubNumber()));
				}
				if(paper.getTopStu()!=null)
				{
					sql1.add(" P.topStu=? ");
					paras.add(String.valueOf(paper.getTopStu()));
				}
				if(paper.getTauthor()!=null)
				{
					sql1.add(" P.tauthor like ? ");
					paras.add("%"+String.valueOf(paper.getTauthor())+"%");
				}
				if(paper.getOauthor()!=null)
				{
					sql1.add(" P.oauthor like ? ");
					paras.add("%"+String.valueOf(paper.getOauthor())+"%");
				}
				if(paper.getMeetClass()!=null)
				{
					sql1.add(" P.meetClass=? ");
					paras.add(String.valueOf(paper.getMeetClass()));
				}
			}
			
			for(int i=0;i<sql1.size();i++)
			{
				sql+="and"+sql1.get(i);
			}
			String[] parameter=new String[paras.size()];
			for(int i=0;i<paras.size();i++)
			{
				parameter[i]=paras.get(i);
			}
			MysqlCrud mysqlcurd=new MysqlCrud();
			List<Map> lists=mysqlcurd.SelectData(sql, parameter);
			//System.out.println(list.size());
			while(j<lists.size()){
				Map map=lists.get(j);
				papers.add(new MapToBean().MapToPaper(map));
				j++;
			}
			return papers;
		}
		
		

}
